<template>
  <div class="container">
    <div class="app-container" style="padding: 20px;">
      <el-row class="header" style="font-size: 14px;">
        <span>一体杆名称：</span>
        <el-input
          v-model="searchForm.poleName"
          placeholder="请输入一体杆名称"
          size="mini"
          style="width: 180px; margin-right: 10px;"
        />
        <span>一体杆编号：</span>
        <el-input
          v-model="searchForm.poleNumber"
          placeholder="请输入一体杆编号"
          size="mini"
          style="width: 180px; margin-right: 10px;"
        />
        <span>处置状态：</span>
        <el-select
          v-model="searchForm.status"
          placeholder="请选择处置状态"
          size="mini"
          style="width: 180px; margin-right: 10px;"
        >
          <el-option label="未派单" value="unassigned" />
          <el-option label="已派单" value="assigned" />
        </el-select>
        <el-button size="mini" type="primary" @click="searchFaults">查询</el-button>
      </el-row>
      <el-divider />
      <el-table :data="faultsList" style="width: 100%; margin-top: 20px;">
        <el-table-column type="index" label="序号" width="80" />
        <el-table-column prop="name" label="一体杆名称" />
        <el-table-column prop="number" label="一体杆编号" />
        <el-table-column prop="type" label="故障类型" />
        <el-table-column prop="status" label="处置状态" />
        <el-table-column prop="time" label="告警时间" />
        <el-table-column label="操作" width="180">
          <template slot-scope="scope">
            <el-button size="mini" @click="assignFault(scope.row)">派单</el-button>
            <el-button size="mini" @click="viewDetails(scope.row)">详情</el-button>
            <el-button size="mini" type="danger" @click="deleteFault(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        layout="prev, pager, next"
        :total="totalFaults"
        :page-size="pageSize"
        style="text-align: right; margin-top: 20px;"
        @current-change="handlePageChange"
      />
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      searchForm: {
        poleName: '',
        poleNumber: '',
        status: ''
      },
      faultsList: [],
      totalFaults: 0,
      pageSize: 10,
      currentPage: 1
    }
  },
  created() {
    this.fetchFaults()
  },
  methods: {
    searchFaults() {
      // 调用搜索故障的 API
      console.log('搜索故障:', this.searchForm)
      this.fetchFaults()
    },
    assignFault(fault) {
      // 调用派单的 API
      console.log('派单故障:', fault)
    },
    viewDetails(fault) {
      // 调用查看详情的 API
      console.log('查看故障详情:', fault)
    },
    deleteFault(id) {
      this.$confirm('确定要删除这条记录吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 调用删除故障的 API
        console.log('删除故障:', id)
      })
    },
    handlePageChange(page) {
      this.currentPage = page
      this.fetchFaults()
    },
    fetchFaults() {
      // 调用获取故障列表的 API
      console.log('获取故障列表:', this.currentPage)
    }
  }
}
</script>

<style scoped>
.container {
  padding: 20px;
}

.header {
  margin-bottom: 20px;
}
</style>
